#pragma once

#include "RBTree.h"

namespace xsc
{
	template<typename K,typename V>
	class map
	{
		struct KeyOfValue
		{
			const K& operator()(const pair<K,V>& kv)
			{
				return kv.first;
			}
		};

		typedef typename RBTree<K, pair<const K, V>, KeyOfValue>::Iterator iterator;
		typedef typename RBTree<K, pair<const K, V>, KeyOfValue>::Const_Iterator const_iterator;

	public:
		iterator begin()
		{
			return tree.Begin();
		}

		iterator end()
		{
			return tree.End();
		}

		const_iterator begin() const
		{
			return tree.Begin();
		}

		const_iterator end() const
		{
			return tree.End();
		}

		pair<iterator,bool> insert(const pair<K,V>& kv)
		{
			return tree.Insert(kv);
		}

		V& operator[](const K& key)
		{
			pair<iterator, bool> ret = tree.Insert({ key, V() });

			return ret.first->second;
		}

	private:
		RBTree<K, pair<const K, V>, KeyOfValue> tree;
	};
}